<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>申请记录修改</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">

<div class="Wrapper">
	<div>
            <div id="pageInTab" class="pageInTab">
                    <form id="cust_apply_add_form">
                        <div class="fieldset1 tabel_col clearFix">
                            <div class="fieldBox col_33">
                                <div class="label">客户名称</div>
			                    <div class="field">
			                        <input name="cstNm" id="cstNm" disabled="disabled" type="text" class="ui-textbox" value="" validate="{required:true}">
			                        <span class="requiredSymbol">*</span>
			                    </div>
                            </div>
                            <div class="fieldBox col_33">
			                    <div class="label">项目所属机构</div>
			                    <div class="field">
			                        <input name="orgNm" id="orgNm" disabled="disabled" type="text" class="ui-textbox" validate="{required:true}">
			                    </div>
			                </div>
                            <div class="fieldBox col_33">
                                <div class="label">收件人</div>
			                    <div class="field">
			                        <input name="rcverNm" id="rcverNm" type="text" class="ui-textbox" value="" placeholder="无特殊情况,请填写商助姓名." validate="{required:true, maxlength:10}">
			                        <span class="requiredSymbol">*</span>
			                    </div>
                            </div>
                            <div class="fieldBox col_33">
			                     <div class="label">联系电话</div>
						        <div class="field">
						           <input name="rcverTel" id="rcverTel" type="text" class="ui-textbox" value="" placeholder="无特殊情况,请填写商助电话." validate="{required:true, maxlength:15}">
						           <span class="requiredSymbol">*</span>
						        </div>
			                </div>
			                <div class="fieldBox col_66">
			                    <div class="label">收件地址</div>
			                    <div class="field">
			                        <input name="rcvAddr" id="rcvAddr" type="text" class="ui-textbox" value="" placeholder="无特殊情况,请填写商助地址." validate="{required:true, maxlength:60}">
			                        <span class="requiredSymbol">*</span>
			                    </div>
			                </div>
                            <div class="fieldBox col_33">
                                <div class="label">开具方式</div>
                                <div class="field">
                                    <input name="billWayCd" id="billWayCd" type="text" class="ui-textbox" value="纸质发票" disabled>
                                </div>
                            </div>
			                <div class="fieldBox col_33">
			                    <div class="label">是否提前开票</div>
			                    <div class="field">
			                        <span id="isPreInv" name="isPreInv"></span>
			                    </div>
			                </div>
			                
			                <div class="fieldBox col_33">
			                     <div class="label">开票人电话</div>
						        <div class="field">
						           <input name="invTel" id="invTel" type="text" class="ui-textbox" value="" validate="{required:false, maxlength:15}">
						        </div>
			                </div>
			                
			                <div class="fieldBox col_33">
			                    <div class="label">开票人开户行</div>
			                    <div class="field">
			                         <select name="invBkCd" id="invBkCd" data-value="" validate="{required:false, select: false}">
			                            <option value="">请选择</option>
			                            <c:forEach items="${selectBkCdList }" var="kv">
											<option value="${kv.key }">${kv.value }</option>
										</c:forEach>
			                		 </select>
			                    </div>
			                </div>
			                
				            <div class="fieldBox col_33">
			                     <div class="label">开票人帐号</div>
						        <div class="field">
						           <input name="invAccNo" id="invAccNo" type="text" class="ui-textbox" value="" validate="{required:false, maxlength:30}">
						        </div>
			                </div>	
			                
			                <div class="fieldBox col_33">
			                     <div class="label">纳税人识别号</div>
						        <div class="field">
						           <input name="invTaxId" id="invTaxId" type="text" class="ui-textbox" value="" validate="{required:false, maxlength:30}">
						        </div>
			                </div>
                            <div class="fieldBox col_33">
                                <div class="label">客户类型</div>
                                <div class="field">
                                    <input name="cstTypCdNm" id="cstTypCdNm"  disabled="disabled" type="text" class="ui-textbox" value="" >
                                </div>
                            </div>
			                <div class="fieldBox col_100">
			                    <div class="label">发票抬头</div>
			                    <div class="field">
			                        <input name="invTitle" id="invTitle" type="text" class="ui-textbox" value="${cstNm }" validate="{required:false, maxlength:20}">
			                    </div>
			                </div>
			                
			                <div class="fieldBox col_100">
			                    <div class="label">开票地址</div>
			                    <div class="field">
			                        <input name="invAddr" id="invAddr" type="text" class="ui-textbox" value="" validate="{required:false, maxlength:100}">
			                    </div>
			                </div>
			                
			                <div class="fieldBox col_100">
								<div class="label">资料上传</div>
								<div class="field">
				                   	<jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
				                   		<jsp:param name="filePath" value="invoice"/>
				                   	</jsp:include>
								</div>
							</div>
							
							<div class="fieldBox col_100">
									<div class="label">资料</div>
									<div class="field">
					                	<jsp:include page="../../system/sysUlFilesRec/sysUlFileRecList.jsp" flush="true" >
					                   		<jsp:param name="pkId" value="${id }"/>
					                   		<jsp:param name="tabNm" value="PRJ_BILL_APPLY"/>
					                 	</jsp:include>
						            </div>
							</div>
			                
			                 <!-- hide data -->
					        <div class="fieldBox col_100" style="display:none;">
					          <div class="field">
					              <input name="applyId" id="applyId" type="text" class="ui-textbox" value="${id}">
					              <input name="orgCd" id="orgCd" type="text" class="ui-textbox" value="${orgCd}">
					          </div>
					        </div>
                        </div>	
                    </form>
                    <div class="sqPanel">
                        <%--<div class="sqPanel_head inL">--%>
                            <%--<div class="btnsBox inLC">--%>
                                <%--<span id="cst_apply_add_btn" onclick="save();" class="sq-button">保存</span>--%>
                            <%--</div>--%>
                            <%--<span>支付表信息</span>--%>
                        <%--</div>--%>
                        <div class="fieldset1 clearFix">
                            <div class="fieldBox">
                                <div class="label"></div>
                                <div class="field">
                                    <span id="cst_apply_add_btn" onclick="save();" class="sq-button sq-button-round">保存</span>
                                </div>
                            </div>
                            <div class="fieldBox" style="display: none">
                                <div class="label"></div>
                                <div class="field">
                                    <input name="cntNo" id="cntNo" data-value="" placeholder="请选择合同号" ltype="combobox">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label"></div>
                                <div class="field">
                                    <input name="feeTypList" id="feeTypList" data-value="" placeholder="请选择费用项" ltype="combobox"    >
                                </div>
                            </div>
                        </div>
                        <!-- 支付表列表 -->
						<div id="invoiceAddGrid" class="sq-grid"></div> 
                    </div>
            </div>
        </div>
</div>
	<script>
        $(function () {

            initForm();
            initData();
            initGrid();

            $("#feeTypList").ligerComboBox({
                valueField: 'key',
                textField: 'value',
                width: 150,
                data: ${feeTyps},
                onChangeValue: function () {
                    searchFeeTyp();
                }
            });

        });
		
		//初始化表单
		function initForm(){
		   $("#cust_apply_add_form").ligerForm({
                validate: true
           });
		}

        function searchFeeTyp() {
            if (!grid) return null;
            var clause = function (rowdata, rowindex) {
                var key = liger.get("feeTypList").getValue();
                if (key) {
                    return rowdata.feeTypCd == (key);
                } else {
                    return true;
                }
            };
            grid.loadData(clause);
        }

		var grid;
		
		//初始化列表
	    function initGrid(){
            var _applyId = $("#applyId").val();
	    	var billTypCdList = [];//模块类型数据
	        <c:if test="${not empty prjBillStsCdList}">
	        	billTypCdList = ${prjBillStsCdList};
	        </c:if>
	        $("#invoiceAddGrid").ligerGrid({
	            usePager: false,
	            url: "<%=path%>/invoice/prjbillfeer/initList.do?applyId="+_applyId,
	            method : 'get',
	            columns: [{
	            	display: '业务模式', 
	            	name: 'bizTypCdNm', 
	            	width: 180, 
	            	align: 'center'}
	             ,{
	                display: '支付表号',
	                name: 'paySchNo',
	                width: 200,
	                align:'center',
	                render: function (rowdata, rowindex, value, column) { 
	            		var h = '';
	            		    h='<a href="javascript:detailPayBtn(';
	                        h+="'"+rowdata.id+"',";
	                        h+="'"+rowdata.paySchId+"',";
	                        h+=')">'+value+'</a>'
	                        return h;
	            		},
	            }, {
	                display: '费用项',
	                name: 'feeTypCdNm',
	                width: 150,
	                align:'center'
	            }, {
	                display: '应收金额(元)',
	                name: 'billAmt',
	                width: 120,
	                align:'right',
	                render:function(rowdata,index,value){
	                    return '&yen;' + FormatMoney(rowdata.billAmt/100);
	                }
	            }, {
	                display: '实收金额(元)',
	                name: 'billAmt',
	                width: 120,
	                align:'right',
	                render:function(rowdata,index,value){
	                    return '&yen;' + FormatMoney(rowdata.billAmt/100);
	                }
	            }, {
	                display: '开票类型',
	                name: 'billTypCdNm',
	                width: 150,
	                align:'center',
	                editor: { type: 'select' , data: billTypCdList, valueField: 'key', textField:'value'}
	            }, {
	                display: '开票状态',
	                name: 'billStsCdNm',
	                width: 100,
	                align:'center'
	            }, {
	                display: '票据号',
	                name: 'billNo',
	                width: 160,
	                align:'left',
                    editor: { type: 'text'}
	            },getGridOperColumnContent()],
	            onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
	            	if (e.selected && e.column.columnname == "billTypCdNm") {
	                    e.record.billTypCd = e.value;
	                    e.value = e.selected[e.column.editor.textField];
	                }
	            },
	            isDisabledSelect: function (item) {
	                if (StringUtils.isNotEmpty(item.billStsCd) && item.billStsCd == CustomerConstant.CODE_PRJ_BILL_STS_CD_2) {
	                	return true;
	                }
	                if (StringUtils.isNotEmpty(item.billStsCd) && item.billStsCd == CustomerConstant.CODE_PRJ_BILL_STS_CD_1) {
	                	return true;
	                }
	                
	                if(item.isDel == CustomerConstant.CODE_PRJ_BILL_R_IS_DEL_2){
	                	return true;
	                }
	            },
	            width: '100%',
	            height:'100%',
				heightDiff:-2,
	            root:'rows',
		        record:'total',
	            rownumbers: true,
	            enabledEdit: true,
	            checkbox:true,
	            fixedCellHeight: false,
	            usePagerOnLessPagesize: false,
	            onAfterShowData: function(currentData) {
	                SetIframe_height();
	                $(".liger_tip").ligerTip();
	            },
                onSuccess: function (data, grid) {
                    grid.loadData(data);
                }
	        });

	        grid = liger.get("invoiceAddGrid");
	        grid.setHeight(100);
	        grid.options.isSingleCheck=false;
	    }
	  	//查看支付表详情
	    function detailPayBtn(id,paySchId){
	    	var editFlag = true;
	    	Add_navTab('tab_prj_quat_prps'+id,'查看支付表','<%=path%>/project/prjprdpayschm/toPrjPrdPaySchMDetailPageBySchId.do?paySchId='+paySchId);
	     }
	  	//获取Grid操作列内容
	    function getGridOperColumnContent(){
	    	 var data = {
	            display: '操作',
	            isSort: false,
	            align:'left',
	            width: 100,
	            render: function (rowdata, rowindex, value){
	            	var h= "";
	            	if (StringUtils.isEmpty(rowdata.billStsCd) && rowdata.isDel == CommonConstant.C_YN_N) {
	            		 h+='<a class="sq-button-hasicon" alt="删除后将无法恢复" href="javascript:delRow(';
		                 h+="'"+rowdata.id+"'";
		                 h+=")\"><i class=\"sqBtnIco_5\"></i>"+LogUtils.LOG_CMM_GRID_BTN_DELETE+"</a>"
	                }
	            	
	            	if(rowdata.isDel == CustomerConstant.CODE_PRJ_BILL_R_IS_DEL_2){//需要恢复删除数据2为正常状态0
                   	 h+='<a class="sq-button-hasicon" alt="恢复" href="javascript:backNormalRow(';
	                    h+="'"+rowdata.id+"'";
	                    h+=")\"><i class=\"sqBtnIco_48\"></i>"+LogUtils.LOG_CMM_GRID_BTN_BACK+"</a>"
                    }
	                return h;
	            }
	    	 }
	    	return data;
	    }
		
		//保存
		function save(){
			var ligerForm = liger.get("cust_apply_add_form");
            if (!ligerForm.valid()) {
                UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
                return false; //验证不通过，不执行以下代码
            }
            var formData = ligerForm.getData();
            var _isPreInv = $('input[name="isPreInv"]:checked ').val();
            formData["isPreInv"] = _isPreInv;
            //获取Grid数据
            var _grid = grid.getSelectedRows();
            
    		var _data = [];
    		for ( var index in _grid) {
    			var obj = {};
    			obj["rId"] = _grid[index].id;
    			obj["billTypCd"] = _grid[index].billTypCd;
    			_data.push(obj);
    		}
    		formData["grid"] = JSON.stringify(_data);
    		//附件
    		var docArray = JSON.stringify(getUploadResultParams());
            formData["docArray"] = docArray;
    		//alert(JSON.stringify(formData));
            var url = '<%=path%>/invoice/prjbillapply/modify.do';
			AjaxUtils.ajaxPost(url, formData, saveCallback, true);
		}
		
		
		//新增回调
		function saveCallback(msg){
			if(msg.success == 1){
				 UIUtils.alertSuccess(msg.info);
				 grid.reload();
				 
				 //刷新附件页面GRID方法和清空上传按钮
				 refreshUlFileRecListByPkId($("#applyId").val(),"PRJ_BILL_APPLY");
				 clearUploadResultParams();
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//删除
		function delRow(_id){
			$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
	   			if(flag == false)return;
	   		 		var url = '<%=path%>/invoice/prjbillfeer/removeById.do';
	         		AjaxUtils.ajaxPost(url, {id:_id}, delRowCallback, true);
	   		});
		}
		
	    //删除回调
	    function delRowCallback(msg){
	    	if(msg.success == 1){
					UIUtils.alertSuccess(msg.info);
					grid.reload();
			}else{
					UIUtils.alertWarning(msg.info);
			}
	    }
	    
	    //恢复
		function backNormalRow(_id){
			$.ligerDialog.confirm(LogUtils.LOG_CMM_BACK_CONFIRM, function (flag) {
	   			if(flag == false)return;
	   		 		var url = '<%=path%>/invoice/prjbillfeer/modifyHoldToNormalById.do';
	         		AjaxUtils.ajaxPost(url, {id:_id}, backNormalRowCallback, true);
	   		});
		}
		
	    //恢复回调
	    function backNormalRowCallback(msg){
	    	if(msg.success == 1){
					UIUtils.alertSuccess(msg.info);
					grid.reload();
			}else{
					UIUtils.alertWarning(msg.info);
			}
	    }
		
		//修改初始化数据
		function initData(){
			var applyId = $("#applyId").val();
	    	if(!applyId)return;
	    	var _url = '<%=path%>/invoice/prjbillapply/getById.do';
	    	AjaxUtils.ajaxGet(_url, {id:applyId}, initCallback, true);
    	}
		
		//初始化回调
		function initCallback(msg){
			if(msg.success == 1){
				 setData(msg.data);//设置数据
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//修改时候设置页面数据
	    function setData(data){
	    	var form = new liger.get("cust_apply_add_form");
	    	form.setData({
	    		rcverNm:data.rcverNm,
	    		rcverTel:data.rcverTel,
	    		rcvAddr:data.rcvAddr,
	    		expCorp:data.expCorp,
	    		trcNo:data.trcNo,
	    		cstNm:data.cstNm,
	    		orgNm:data.buOrgCdNm,
	    		invTel:data.invTel,
	    		invAccNo:data.invAccNo,
	    		invTaxId:data.invTaxId,
	    		invTitle:data.invTitle,
	    		invAddr:data.invAddr,
	    		invBkCd:data.invBkCd,
                cstTypCdNm:data.cstTypNm
	    	});
	    	$("#isPreInv").html(data.isPreInvNm);
	    	//$("input[name='isPreInv'][value="+data.isPreInv+"]").prev(".l-radio").click();
		};
		
	</script>

</body>
</html>